package com.framework.common.oss;

import com.framework.common.config.SystemConfigName;
import com.framework.common.utils.Constant;
import com.framework.common.utils.QuickHelper;
import com.framework.common.utils.SpringContextUtils;
import org.springframework.core.env.Environment;

/**
 * 文件上传Factory
 */
public final class OSSFactory {

	private static CloudStorageConfig config;
	public static CloudStorageDirectory DirectoryConfig;
	static {

		Environment env =SpringContextUtils.applicationContext.getEnvironment();
		OSSFactory.config = QuickHelper.getConfigValue(SystemConfigName.OSS_SDK_CONFIG, CloudStorageConfig.class);
		OSSFactory.DirectoryConfig = QuickHelper.getConfigValue(SystemConfigName.STORAGE_DIRECTORYCONFIG, CloudStorageDirectory.class);
	}

	public static CloudStorageService create() {
		if (config.getType() == Constant.CloudService.QINIU.getValue()) {
			return new QiniuCloudStorageService(config);
		} else if (config.getType() == Constant.CloudService.ALIYUN.getValue()) {
			return new AliyunCloudStorageService(config);
		} else if (config.getType() == Constant.CloudService.QCLOUD.getValue()) {
			return new TencentCosCloudStorageService(config);
		}
		return null;
	}

}
